﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jacaranda.Model
{
    public class LeftFunction : BinaryFunction
    {
        internal override string GenerateSql(Type propertyEntityType)
        {
            string fieldName = Operand1.GenerateSql(propertyEntityType);

            if (Operand2 is ComparableNode)
            {
                return string.Format("LEFT({0}, {1})", fieldName, (Operand2 as ComparableNode).GenerateSql(propertyEntityType));
            }
            else
            {
                return string.Format("LEFT({0}, {1})", fieldName, (int)Operand2);
            }
        }
    }
}
